import java.util.ArrayList;
import java.util.Objects;

public class try_ {
    public static void main(String[] args){
        ArrayList<Student> list = new ArrayList<>();
        Student s1 = new Student("s1", "000001", "男", "123456", "School", 20);
        Student s2 = new Student("s2", "000002", "男", "123456", "school", 20);
        Student s3 = new Student("s3", "000003", "男", "123456", "school", 20);
        Student s4 = new Student("s4", "000004", "男", "123456", "school", 20);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        for(int i = 0; i < list.size(); i ++){
            Student cur = list.get(i);
            System.out.println(cur.getUsername() + "," + cur.getAge());
        }
        int inx = getIndex(list, "s2");
        System.out.println("index:" + inx);
    }
    public static int getIndex(ArrayList<Student> list, String username){
        for(int i = 0; i < list.size(); i ++){
            if(Objects.equals(list.get(i).getUsername(), username)){
                return i;
            }
        }
        return -1;
    }
    public static int getIndex(ArrayList<Student> list, int id){
        for(int i = 0; i < list.size(); i ++){
            if(Objects.equals(list.get(i).getId(), id)){
                return i;
            }
        }
        return -1;
    }
}